<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>我的</title>
    <link href="../../css/mui.min.css" rel="stylesheet"/>
    <link href="../../css/list.css" rel="stylesheet" />
    <link href="../../admin/css/style.css" rel="stylesheet" />
    <script src="../../js/app.js"></script>
    <script src="../../js/mui.min.js"></script> 
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">我的资讯</h1>
		</header>
		<div class="mui-content" id="pullrefresh">
			<ul class="mui-table-view" >
			       <div class="friend-list-left" id="news"></div>
		    </ul>
	    </div>
	</body>
	<script type="text/javascript">
		var content=document.getElementById("news");
//		localStorage.setItem('list','[]');//清空本地数据 
mui.init({  
		pullRefresh: {  
		container: '#pullrefresh', //触发刷新功能的id标签
		down: {  //触发下拉函数
		height:50,// 可选.默认50.触发上拉加载拖动距离
        auto:false,// 可选,默认false.自动上拉加载一次
        style:'circle',//必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
      	color:'#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色
        range:'100px', //可选 默认100px,控件可下拉拖拽的范围
     	offset:'50px', //可选 默认0px,下拉刷新控件的起始位置
		contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
		contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
		contentrefresh : "正在刷新...",//可选，正在刷新状态时，下拉刷新控件上显示的标题内容
		callback: pulldownRefresh
	},
		up : {//触发上拉
		height:50,// 可选.默认50.触发上拉加载拖动距离
        auto:false,// 可选,默认false.自动上拉加载一次
		contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
		contentnomore:'没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
		callback :pullupRefresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
	}
              }  
});  
//* 下拉刷新具体业务实现 
function pulldownRefresh() { 
		setTimeout(function () { 
		//            	document.getElementById('news').innerHTML='';
		news(0);//获取数据
		mui('#pullrefresh').pullRefresh().endPulldownToRefresh();//关闭上拉刷新样式
		}, 1500);  //1500毫秒触发
} 
 //* 上拉加载具体业务实现 
function pullupRefresh() { 
		setTimeout(function () { 
		news(1);//获取数据
		mui('#pullrefresh').pullRefresh().endPullupToRefresh();//关闭下拉加载样式
		}, 1500);  //1500毫秒触发
} 
news();
var	p= 0;
function news(num){//我的微博帖
				if(num==1){p=p+1}else{p=0;document.getElementById("news").innerHTML='';};
			apptoken['p']= p;
			apptoken['act']= 'list';
			 mui.post(home.hos+'/news/admin',apptoken,function(data){
//			 alert(data);
			var result=JSON.parse(data);
			 var val='';
			 var pic='';
		for(var i=0;i<result.length;i++){
			if(result[i].pic===null || result[i].pic==='' || result[i].pic==='undefined'){
				pic='';
			}else{
			pd=result[i].pic.indexOf(",")==-1;//判断字符串里是否含有逗号如果不含有
			if(pd!=-1){
				var rpic=result[i].pic.split(",");
				pic='<img class="mui-media-object mui-pull-left" style="margin-right:10px" src="'+home.uploads+'/img/news/cut'+rpic[0]+'" onerror="this.onerror=null;this.src=\''+home.uploads+'/img/news/min'+rpic[0]+'\'" />';}
			}
			liststyle(result[i].id,getFormatCodec(result[i].content.substr(0,38)),result[i].refresh,pic,result[i].comment,result[i].collect,result[i].zan,result[i].relationoff);
			}
				//服务器返回响应，根据响应结果，分析是否登录成功；
			},'text');
}
function  liststyle(tid,contents,refreshtime,pic,comment,collect,zan,relationoff){
	var datej = new Date();
   	datej.setTime(datej.getTime());
   	var day=datej.getDate();//获取当前日期
	var refresh='';
			var retime=new Date(parseInt(refreshtime) * 1000).format('yyyy-MM-dd hh:mm:ss');
			var day2=new Date(parseInt(refreshtime) * 1000).format('d');//服务器刷新日期
			if(day!=day2){//判断如果不=今天，则可以刷新
				refresh='<span id="refresh'+tid+'" style="display:block;padding-left:20px;float:left" onclick="_refresh('+tid+');" >[刷新]</span>';
			}
if(relationoff==1){
	relationtext='撤销关联';
}
if(relationoff==0){
	relationtext='推送关联';
}
	content.innerHTML+='<div id="list'+tid+'" ><li class="mui-table-view-cell mui-media"><div class="mui-media-body" id="'+tid+'" onclick="goto(\'news\',\'home\',\'detail\','+tid+')" >'+pic+contents+'<p class="mui-ellipsis">'+retime+'</p></div><p class="mui-ellipsis"><span style="margin-right:20px">回复:'+comment+'</span><span style="margin-right:20px">收藏:'+collect+'</span><span style="margin-right:20px">赞:'+zan+'</span></p><div style="color:red"><div onclick="goto(\'news\',\'admin\',\'modify\','+tid+')" style="float:left;">[编辑]</div>'+refresh+'<div onclick="_delete('+tid+')" style="float:left;padding-left:20px;">[删除]</div><div style="padding-left:20px;float:left;" onclick="modify('+tid+',\'relationoff\')"  value="'+relationoff+'">[<span id="relationoff'+tid+'">'+relationtext+'</span>]</div></div></div></li>';
}

function _delete(thisid){
		 	if(!window.confirm('你确定要删除吗。')){
		 		plus.ui.toast("已取消");
                 return false;
            }
		 	apptoken['tid']=thisid;
		 	apptoken['act']= 'delete';
		mui.post(home.hos+'/news/admin',apptoken,function(data){
			alert(data);
			if(data==200){
			var tid=document.getElementById('list'+thisid);
				content.removeChild(tid);//删除div
		plus.ui.toast("删除成功");
		}else{
			plus.ui.toast("操作失败",data);
		}
		},'text')
	}
function _refresh(thisid){
		 if(!window.confirm('每天只能刷新一次，你确定要刷新吗？')){
		 		plus.ui.toast("已取消");
                 return false;
         }
		apptoken['tid']=thisid;
		apptoken['act']= 'refresh';
		mui.post(home.hos+'/news/admin',apptoken,function(data){
			if(data==200){
				document.getElementById('refresh'+thisid).style.display='none';//隐藏刷新按钮
				 var tid=document.getElementById('list'+thisid);
				 appendChild("news",tid.innerHTML,1);
				content.removeChild(tid);//删除div
				plus.ui.toast("刷新成功");
			}else{
				plus.ui.toast("操作失败"+data);		
			}
//		history.go(0);
		},'text')
	}

function modify(tid,act){
	relationoff=document.getElementById('relationoff'+tid);
	if(relationoff.innerHTML=='推送关联'){
		apptoken['v']=1;
	}else{
		apptoken['v']=0;
	}
	if(!window.confirm('您确定要'+relationoff.innerHTML+'码？推送展现在被关联的项目/主题页面的新闻部位;')){
		 		plus.ui.toast("已取消");
                 return false;
            }
	apptoken['tid']=tid ||'';
	apptoken['k']=act||'relationoff';
	apptoken['act']='modify';
	mui.post(home.hos+'/news/admin',apptoken,function(data){//获取关联数据
//		alert(data);
	 	if(data==200){
	 		if(relationoff.innerHTML=='推送关联'){
			relationoff.innerHTML='撤销关联';
			}else{
			relationoff.innerHTML='推送关联';
			}
	 		plus.ui.toast('修改成功');
	 	}else{
	 		plus.ui.toast('修改失败');
	 	}})
}
//function goto(thisid,method){//修改微博
//		//数据库存储当前点击id值
//localStorage.newstid=thisid; 
//mui.openWindow('../news/'+method+'.html');
//}
	</script>
</html>
